<template>
  <div class="settings-page">
    <Header />
    
    <main class="main">
      <div class="container">
        <div class="settings-header">
          <h1 class="settings-title">设置</h1>
          <p class="settings-subtitle">个性化您的购物体验</p>
        </div>

        <div class="settings-content">
          <div class="settings-section">
            <h2 class="section-title">外观设置</h2>
            <div class="setting-item">
              <div class="setting-info">
                <h3>主题模式</h3>
                <p>选择您喜欢的主题颜色</p>
              </div>
              <div class="setting-control">
                <button 
                  class="theme-btn" 
                  :class="{ active: settingsStore.theme === 'light' }"
                  @click="settingsStore.toggleTheme()"
                >
                  <i class="fas fa-sun"></i>
                  浅色模式
                </button>
                <button 
                  class="theme-btn" 
                  :class="{ active: settingsStore.theme === 'dark' }"
                  @click="settingsStore.toggleTheme()"
                >
                  <i class="fas fa-moon"></i>
                  深色模式
                </button>
              </div>
            </div>
          </div>

          <div class="settings-section">
            <h2 class="section-title">语言设置</h2>
            <div class="setting-item">
              <div class="setting-info">
                <h3>界面语言</h3>
                <p>选择您偏好的语言</p>
              </div>
              <div class="setting-control">
                <select v-model="settingsStore.language" class="language-select">
                  <option value="zh-CN">简体中文</option>
                  <option value="en-US">English</option>
                </select>
              </div>
            </div>
          </div>

          <div class="settings-section">
            <h2 class="section-title">通知设置</h2>
            <div class="setting-item">
              <div class="setting-info">
                <h3>推送通知</h3>
                <p>接收商品促销和订单状态通知</p>
              </div>
              <div class="setting-control">
                <label class="toggle-switch">
                  <input 
                    type="checkbox" 
                    v-model="settingsStore.notifications"
                    @change="settingsStore.toggleNotifications()"
                  >
                  <span class="toggle-slider"></span>
                </label>
              </div>
            </div>
          </div>

          <div class="settings-section">
            <h2 class="section-title">数据设置</h2>
            <div class="setting-item">
              <div class="setting-info">
                <h3>自动保存</h3>
                <p>自动保存您的购物车和偏好设置</p>
              </div>
              <div class="setting-control">
                <label class="toggle-switch">
                  <input 
                    type="checkbox" 
                    v-model="settingsStore.autoSave"
                    @change="settingsStore.toggleAutoSave()"
                  >
                  <span class="toggle-slider"></span>
                </label>
              </div>
            </div>
          </div>

          <div class="settings-section">
            <h2 class="section-title">账户设置</h2>
            <div class="setting-item">
              <div class="setting-info">
                <h3>个人信息</h3>
                <p>管理您的账户信息</p>
              </div>
              <div class="setting-control">
                <button class="btn btn-secondary" @click="handleEditProfile">
                  <i class="fas fa-edit"></i>
                  编辑资料
                </button>
              </div>
            </div>
            <div class="setting-item">
              <div class="setting-info">
                <h3>安全设置</h3>
                <p>修改密码和安全设置</p>
              </div>
              <div class="setting-control">
                <button class="btn btn-secondary" @click="handleSecuritySettings">
                  <i class="fas fa-shield-alt"></i>
                  安全设置
                </button>
              </div>
            </div>
          </div>

          <div class="settings-section">
            <h2 class="section-title">其他</h2>
            <div class="setting-item">
              <div class="setting-info">
                <h3>清除缓存</h3>
                <p>清除本地缓存数据</p>
              </div>
              <div class="setting-control">
                <button class="btn btn-secondary" @click="handleClearCache">
                  <i class="fas fa-trash"></i>
                  清除缓存
                </button>
              </div>
            </div>
            <div class="setting-item">
              <div class="setting-info">
                <h3>关于我们</h3>
                <p>查看应用版本和相关信息</p>
              </div>
              <div class="setting-control">
                <button class="btn btn-secondary" @click="handleAbout">
                  <i class="fas fa-info-circle"></i>
                  关于
                </button>
              </div>
            </div>
          </div>
        </div>
      </div>
    </main>

    <Footer />
  </div>
</template>

<script setup lang="ts">
import { useSettingsStore } from '@/stores/settings'
import Header from '@/components/Header.vue'
import Footer from '@/components/Footer.vue'

const settingsStore = useSettingsStore()

// 处理各种设置操作
const handleEditProfile = () => {
  alert('编辑资料功能开发中...')
}

const handleSecuritySettings = () => {
  alert('安全设置功能开发中...')
}

const handleClearCache = () => {
  if (confirm('确定要清除所有缓存数据吗？')) {
    localStorage.clear()
    alert('缓存已清除')
  }
}

const handleAbout = () => {
  alert('视分享商城 v1.0.0\n© 2024 视分享商城. 保留所有权利.')
}
</script>

<style scoped>
.settings-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.settings-header {
  text-align: center;
  margin-bottom: 40px;
}

.settings-title {
  font-size: 32px;
  font-weight: 700;
  color: #2d3436;
  margin-bottom: 10px;
}

.settings-subtitle {
  font-size: 16px;
  color: #636e72;
}

.settings-content {
  max-width: 800px;
  margin: 0 auto;
}

.settings-section {
  background: white;
  border-radius: 16px;
  padding: 24px;
  margin-bottom: 24px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.section-title {
  font-size: 20px;
  font-weight: 600;
  color: #2d3436;
  margin-bottom: 20px;
  border-bottom: 2px solid #f8f9fa;
  padding-bottom: 12px;
}

.setting-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 0;
  border-bottom: 1px solid #f8f9fa;
}

.setting-item:last-child {
  border-bottom: none;
}

.setting-info h3 {
  font-size: 16px;
  font-weight: 600;
  color: #2d3436;
  margin-bottom: 4px;
}

.setting-info p {
  font-size: 14px;
  color: #636e72;
  margin: 0;
}

.setting-control {
  display: flex;
  align-items: center;
  gap: 12px;
}

.theme-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border: 2px solid #e9ecef;
  border-radius: 8px;
  background: white;
  color: #636e72;
  cursor: pointer;
  transition: all 0.3s ease;
  font-size: 14px;
}

.theme-btn:hover {
  border-color: #667eea;
  color: #667eea;
}

.theme-btn.active {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-color: transparent;
  color: white;
}

.language-select {
  padding: 8px 12px;
  border: 2px solid #e9ecef;
  border-radius: 8px;
  background: white;
  color: #495057;
  font-size: 14px;
  cursor: pointer;
}

.language-select:focus {
  outline: none;
  border-color: #667eea;
}

.toggle-switch {
  position: relative;
  display: inline-block;
  width: 50px;
  height: 24px;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #ccc;
  transition: 0.3s;
  border-radius: 24px;
}

.toggle-slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: 0.3s;
  border-radius: 50%;
}

input:checked + .toggle-slider {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

input:checked + .toggle-slider:before {
  transform: translateX(26px);
}

.btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.3s ease;
}

.btn-secondary {
  background: #f8f9fa;
  color: #495057;
}

.btn-secondary:hover {
  background: #e9ecef;
  color: #2d3436;
}

@media (max-width: 768px) {
  .settings-content {
    padding: 0 16px;
  }
  
  .setting-item {
    flex-direction: column;
    align-items: flex-start;
    gap: 16px;
  }
  
  .setting-control {
    width: 100%;
    justify-content: flex-end;
  }
  
  .theme-btn {
    flex: 1;
    justify-content: center;
  }
}
</style> 